from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("C:\Program Files\driver\chromedriver.exe")
driver.maximize_window()

driver.get("https://www.baidu.com")
time.sleep(3)

# # 鼠标双击
# element_button = driver.find_element(By.CSS_SELECTOR, "#su")
# ActionChains(driver).double_click(element_button).perform()

# # 鼠标悬停
# element_setting = driver.find_element(By.XPATH, "//span[text()='设置']")
# ActionChains(driver).move_to_element(element_setting).perform()

# 百度输入框输入：坚果
element_input = driver.find_element(By.CSS_SELECTOR, "#kw")
element_input.send_keys("坚果")
time.sleep(2)
# 删除键，删除：果
element_input.send_keys(Keys.BACK_SPACE)
time.sleep(2)
# 输入空格
element_input.send_keys(Keys.SPACE)
time.sleep(2)
# 再输入python
element_input.send_keys("python")
time.sleep(2)
# 全选
element_input.send_keys(Keys.CONTROL, 'a')
time.sleep(2)
# 复制
element_input.send_keys(Keys.CONTROL, 'c')
time.sleep(2)
# 粘贴
element_input.send_keys(Keys.CONTROL, 'v')
time.sleep(2)
element_input.send_keys(Keys.CONTROL, 'v')
time.sleep(2)
element_input.send_keys(Keys.CONTROL, 'v')
time.sleep(2)
element_input.send_keys(Keys.CONTROL, 'v')

time.sleep(5)
driver.quit()